#!/usr/bin/python

#convert amsol (mol2 file) to amber tables

import sys, string
from openeye.oechem import *


#Name of input file
input = sys.argv[1]






#-----------------------------
#Main

ifs = oemolistream(input)

mol = OEGraphMol()



vdw_dict ={'Du':'20', 'C.2':' 1', 'C.ar':' 1', 'N.pl3':' 8', 'N.ar':' 8',  'N.am':' 8', 'O.co2':'11', 'O.2':'11', 'O.3':'12', 'P.3':'13', 'N.2':' 8', 'C.3':' 5', 'H':' 7', 'S.3':'14'}
start = 'FALSE'

out_file_1 = open('prot.table.ambcrg.ambH.new', 'w')
out_file_2 = open('amb.crg.oxt.new', 'w')
total_charge = 0

while OEReadMolecule(ifs, mol):
	counter = 0
	for atom in mol.GetAtoms():
		charge= atom.GetPartialCharge()
		atom_name = atom.GetName()
		atom_type_number = vdw_dict[atom.GetType()]

		while len(atom_name) < 3:
			atom_name= atom_name + ' '

		line = ' ' +atom_name + '   NAP       ' + '%6.3f'%charge + ' ' + atom_type_number + '\n'
     		out_file_1.write(line)
     		line = atom_name + '   NAP       ' + '%6.3f'%charge + '\n'
     		out_file_2.write(line)
		total_charge = total_charge + charge

		counter = counter + 1

   
       
print "charge " + str(total_charge)






